//
//  AddContactViewController.m
//  OAProject
//
//  Created by yhj on 2017/3/24.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "AddContactViewController.h"

@interface AddContactViewController ()<UITextFieldDelegate>

@end

@implementation AddContactViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title=@"添加";

    [self.view addSubview:[self addContactView]];
}

-(UIView *)addContactView
{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0,64,APPW,0)];
    setViewHeight_Add(view,kmargin*2);

    // 姓名
    LabelTextFieldView *nameView=[[LabelTextFieldView alloc]initWithTitle:@"姓  名" placeholder:@"请输入联系人姓名"];
    nameView.frame=CGRectMake(kmargin*2,view.frame.size.height,APPW-kmargin*4,kmargin*3.5);
    [view addSubview:nameView];
    nameView.textField.delegate=self;
    setViewHeight_Add(view,kmargin*4);

    // 所在公司
    LabelTextFieldView *companyView=[[LabelTextFieldView alloc]initWithTitle:@"公  司" placeholder:@"请输入所在公司"];
    companyView.frame=CGRectMake(kmargin*2,view.frame.size.height,APPW-kmargin*4,kmargin*3.5);
    [view addSubview:companyView];
    companyView.textField.delegate=self;
    setViewHeight_Add(view,kmargin*4);

    // 所在公司编号ID
    LabelTextFieldView *companyIDView=[[LabelTextFieldView alloc]initWithTitle:@"公司编号" placeholder:@"请输入公司编号"];
    companyIDView.frame=CGRectMake(kmargin*2,view.frame.size.height,APPW-kmargin*4,kmargin*3.5);
    [view addSubview:companyIDView];
    companyIDView.textField.delegate=self;
    setViewHeight_Add(view,kmargin*4);

    // 邮箱
    LabelTextFieldView *emailView=[[LabelTextFieldView alloc]initWithTitle:@"邮  箱" placeholder:@"请输入邮箱"];
    emailView.frame=CGRectMake(kmargin*2,view.frame.size.height,APPW-kmargin*4,kmargin*3.5);
    [view addSubview:emailView];
    emailView.textField.delegate=self;
    setViewHeight_Add(view,kmargin*4);

    // 手机号
    LabelTextFieldView *phoneView=[[LabelTextFieldView alloc]initWithTitle:@"手机号" placeholder:@"请输入手机号"];
    phoneView.frame=CGRectMake(kmargin*2,view.frame.size.height,APPW-kmargin*4,kmargin*3.5);
    [view addSubview:phoneView];
    phoneView.textField.delegate=self;
    setViewHeight_Add(view,kmargin*4);

    UIButton *OKBtn=[AppUI createButtonWithText:@"确  认" andWithTextColor:WhiteColor andWithFontfloat:16 andWithBtnAction:^{

        [API AddUserWithName:nameView.textField.text phone:phoneView.textField.text memberID:companyIDView.textField.text email:emailView.textField.text passwd:[Util getUserDefaultObjectForKey:@"passwd"] success:^(id res) {

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                [self.navigationController popViewControllerAnimated:NO];
            });

        } failure:^(NSInteger stateCode) {

        }];

    }];
    OKBtn.backgroundColor=MainColor;
    ViewBorderRadius(OKBtn,kmargin,1,ClearColor);
    [view addSubview:OKBtn];
    OKBtn.frame=CGRectMake(kmargin*4,view.frame.size.height+kmargin*2,APPW-kmargin*8,kmargin*4);
    setViewHeight_Add(view,kmargin*4);

    return view;
}

@end
